package com.hx.juc.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * Created  on 2019/04/29.
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "\t上网晚自习，准备回宿舍");
                //计数，相当于减减
                try {
                    Thread.sleep(3000);
                }catch (Exception ignore){}
                countDownLatch.countDown();
            }, String.valueOf(i)).start();

        }
//        countDownLatch.await();
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t班长关门");
    }

}
